package com.kevis.zhunblog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kevis.zhunblog.core.dto.PageDomain;
import com.kevis.zhunblog.core.dto.query.CommonClassQuery;
import com.kevis.zhunblog.core.dto.query.CommonInfoQuery;
import com.kevis.zhunblog.core.entities.ArticleEntity;
import com.kevis.zhunblog.core.entities.ClassArticleEntity;
import com.kevis.zhunblog.mapper.ArticleMapper;
import com.kevis.zhunblog.service.ArticleService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
@CacheConfig(cacheNames={"ArticleServiceImpl"})
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, ArticleEntity>
    implements ArticleService{
    @Cacheable(keyGenerator = "selfKeyGenerate")
    public PageInfo<ArticleEntity> getPageList(CommonInfoQuery query, PageDomain pageDomain) {
        LambdaQueryWrapper<ArticleEntity> wrapper = new LambdaQueryWrapper<>();
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<ArticleEntity> list = super.list(wrapper);
        return new PageInfo<>(list);
    }

    @Cacheable(keyGenerator = "selfKeyGenerate")
    public IPage<ArticleEntity> getPageList(CommonInfoQuery query, Page<ArticleEntity> page) {
        IPage<ArticleEntity> result = new Page<ArticleEntity>();
        LambdaQueryWrapper<ArticleEntity> wrapper = new LambdaQueryWrapper<>();
        this.page(page, wrapper);
        return page;
    }
}




